define(function (require, exports, module) {
	'use strict';
	
	var rk = require('rk');
	// require('commonjs');

	$.widget('rk.pageSearchBarCtrl', {
		_create: function () {
			var me = this;
			var elem = me.element;
			me._listeners();
		},
		_listeners:function(){
			var me = this,
				$elem = this.element;
			me.$input = $elem.find('input');
			me.$lnk = $elem.find('a');
			me.$input.on('keypress', function(evt) {
				evt.keyCode == 13 && me.$lnk.trigger('click');
			});
			me.$input.on('focus',function(){
				$('.page-topsec-inputbox').addClass('active');
			}).on('blur',function(){
				$('.page-topsec-inputbox').removeClass('active');
			});
			me.$lnk.on('click', function(evt) {
				var act = $(this).attr("act");
				/*if (act == "first_search") {
					evt.stopPropagation();
					var btn = $(this);
					btn.hide();
					$('.page-topsec-area').addClass('page-topsec-area-bg');
					$('.page-topsec-inputbox').find('input').css('width',0);
					$('.page-topsec-inputbox').show();
					$('.page-topsec-inputbox').find('input').animate({
						width:300
					},300, function(){
						$elem.find("input[act=keyword]").focus();
					});
				} else if (act == "input_search") {*/
					evt.preventDefault();
					var keyword = $.trim(me.$input.val());
					if (keyword) {
						window.location.href = '/search.action?parentTabName=crm&keyword=' + encodeURIComponent(keyword);
					} else {
						//$.msg('请输入要搜索的内容');
						$.msg(rk.i18n('ALLSEARCH_INPUT_CONTENT'));
					}
				//}
			});
			/*$('.page-topsec-inputbox').click(function(e){
				 e.stopPropagation();
			});
			$(document).on('click',function(e){
				$('.page-topsec-inputbox').find('input').animate({
						width:0 
				},300,function(){
					$elem.find('a[act="first_search"]').show();
					$('.page-topsec-inputbox').hide();
					$('.page-topsec-inputbox').find('input').css('width',300);
					$('.page-topsec-area').removeClass('page-topsec-area-bg');
				});
			});*/
		},
		_init: function(){
			var me = this;
			var elem = me.element;

			/*elem.find('a.header_show_button').click(function(){
				alert('搜索');
			});*/
		}
	});
});